package ${basePackage}.controller<#if (sign!=null||sign=="")>.${sign}</#if>;
import ${basePackage}.e<#if (sign!=null||sign=="")>.${sign}</#if>.${modelNameUpperCamel};
import ${basePackage}.service<#if (sign!=null||sign=="")>.${sign}</#if>.${modelNameUpperCamel}Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sservice.base.entity.dto.BaseResult;
import com.sservice.base.entity.dto.ListResult;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 *
 * Created by ${author} on ${date}.
 */
@Controller
@RequestMapping("/admin/${baseRequestMapping}/")
public class ${modelNameUpperCamel}Controller {

    @Autowired
    ${modelNameUpperCamel}Service ${modelNameLowerCamel}Service;

    @RequestMapping(value="add",method = RequestMethod.POST)
    @ResponseBody
    public BaseResult add(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        return new BaseResult(true,String.valueOf(${modelNameLowerCamel}Service.save(${modelNameLowerCamel})),200);
    }

    @RequestMapping(value="delete/{id}",method = RequestMethod.POST)
    @ResponseBody
    public BaseResult delete(@RequestParam Integer id) {
        return new BaseResult(true,String.valueOf(${modelNameLowerCamel}Service.deleteById(id)),200);
    }

    @RequestMapping(value="update",method = RequestMethod.POST)
    @ResponseBody
    public BaseResult update(${modelNameUpperCamel} ${modelNameLowerCamel}) {
        return new BaseResult(true,String.valueOf(${modelNameLowerCamel}Service.update(${modelNameLowerCamel})),200);
    }

    @RequestMapping("detail/{id}")
    @ResponseBody
    public BaseResult detail(@RequestParam Integer id) {
        ${modelNameUpperCamel} ${modelNameLowerCamel} = ${modelNameLowerCamel}Service.findById(id);
        return new BaseResult(true,${modelNameLowerCamel});
    }

    @RequestMapping("list")
    @ResponseBody
    public ListResult list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<${modelNameUpperCamel}> list = ${modelNameLowerCamel}Service.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return new ListResult(true, pageInfo);
    }
}
